import unittest
from api.ihrm_emp_curd import IhrmEmpCURD
from common.assert_util import assert_util
from parameterized import parameterized
from common.get_headers import get_headers
from common.read_json_util import read_json_data
from common.text import generate_unique_mobile


class TestEmp(unittest.TestCase):

    def setUp(self):
        self.authorization = get_headers().get("Authorization")

    @parameterized.expand(read_json_data("../data/text_emp.json"))
    def test01_add_emp(self, desc, json_data, status_code, success, code, message):
        # 准备数据
        header = {"Content-Type": "application/json", "Authorization": f"Bearer {self.authorization}"}

        # 如果JSON数据中没有提供手机号，则自动生成一个
        if not json_data.get("mobile"):
            json_data["mobile"] = generate_unique_mobile()
            print(f"自动生成手机号: {json_data['mobile']}")

        # 调用自己的封装
        resp = IhrmEmpCURD.add_emp(header, json_data)
        print(desc, ":", resp.json())
        # 断言
        assert_util(self, resp, status_code, success, code, message)